package com.magicmovie.api.controller;

import com.google.common.collect.Maps;
import com.magicmovie.api.service.BannerService;
import com.magicmovie.api.service.DictionaryService;
import com.magicmovie.api.service.IndexCategoryService;
import com.magicmovie.api.service.MovieService;
import com.magicmovie.entity.Banner;
import com.magicmovie.entity.IndexCategory;
import com.magicmovie.util.common.AjaxMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class IndexController {
    @Autowired
    private BannerService bannerService;
    @Autowired
    private IndexCategoryService indexCategoryService;
    @Autowired
    private MovieService movieService;
    @Autowired
    private DictionaryService dictionaryService;

    @RequestMapping(value = "/api/index/index",method = RequestMethod.GET)
    public AjaxMsg index(){
        List<Banner> banner = bannerService.findAll();
        List<IndexCategory> indexCategory = indexCategoryService.findAll();
        for (IndexCategory ic: indexCategory) {
            List<Map<String, Object>> movies = movieService.findByIndexCategoty(ic.getId());
            ic.setMovies(movies);
        }
        List<Map<String, Object>> appName = dictionaryService.findByKeyNo("APP_NAME");
        Map<String,Object> result = Maps.newHashMap();
        result.put("banner",banner);
        result.put("indexCategory",indexCategory);
        result.put("appName",appName);
        return new AjaxMsg(result);
    }
}
